X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id e9OKm7324919
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1617
>>> Parvinder Kaur <kaurp@cs.ucdavis.edu> 00-10-24 11:10:12 AM >>> wrote:
Hi,
I have another problem that I could use help figuring out. I'm
suppose to count the number of lines in a text. The lines should be
stored in a table as the key and it's associated value is the number of
times it occurred within the text. i.e.
Hi there
How are you
Hi there
will look like this
Hi there 2
How are you 1
Any help or suggestions will be greatly appreciated.
Thanks,
Cos :)
>>>
Oh, what fun! Here is my solution, coded for clarity, I hope:
procedure main()
t := table(0)
while line := read() do {
t[line] +:= 1
}
every line := key(t) do
write(line, " ", t[line])
exit()
end
which, on reading
Hi there
How are you
Hi there<EOF>
writes
How are you 1
Hi there 2
However, on reading
Hi there
How are you
Hi there
<EOF>
writes
1
How are you 1
Hi there 2
In other words, watch out for the empty line that might be found at the end!
By the way, the two supposedly identical lines in your sample data were not. One of them had a trailing blank at the end! I had to edit it to get your intended result.
Charles Hethcoat
>>> Parvinder Kaur <kaurp@cs.ucdavis.edu> 00-10-24 11:10:12 AM >>>
Hi,
I have another problem that I could use help figuring out. I'm
suppose to count the number of lines in a text. The lines should be
stored in a table as the key and it's associated value is the number of
times it occurred within the text. i.e.
Hi there
How are you
Hi there
will look like this
Hi there 2
How are you 1
Any help or suggestions will be greatly appreciated.